﻿using Microsoft.Xna.Framework;

using HMEngine.HMCameras;
using HMEngine.HMObjects;

namespace HMEngine.HMEffects {
    public class HMShader : HMEffect {
        public HMShader(string asset) : base(asset) { }

        internal override void SetParameters(HMObject myObject) {
            Matrix World =
                HMCameraManager.ActiveCamera.World *
                Matrix.CreateScale(myObject.Scaling) *
                Matrix.CreateFromQuaternion(myObject.Rotation) *
                Matrix.CreateTranslation(myObject.Position);

            if (null != myEffect.Parameters["World"]) myEffect.Parameters["World"].SetValue(World);
            if (null != myEffect.Parameters["View"])
                myEffect.Parameters["View"].SetValue(HMCameraManager.ActiveCamera.View);
            if (null != myEffect.Parameters["Projection"])
                myEffect.Parameters["Projection"].SetValue(HMCameraManager.ActiveCamera.Projection);
            if (null != myEffect.Parameters["EyePosition"])
                myEffect.Parameters["EyePosition"].SetValue(HMCameraManager.ActiveCamera.Position);
            if (null != myEffect.Parameters["LightDirection"])
                myEffect.Parameters["LightDirection"].SetValue(new Vector3(1, -1, -1));
            if (null != myEffect.Parameters["LightDiffuseColor"])
                myEffect.Parameters["LightDiffuseColor"].SetValue(new Vector3(0.5f));
            if (null != myEffect.Parameters["LightSpecularColor"])
                myEffect.Parameters["LightSpecularColor"].SetValue(new Vector3(0.5f));

            base.SetParameters(myObject);
        }
    }
}